package database

import (
	"github.com/go-redis/redis"
	"os"
	"strconv"
)

var (
	Redis *redis.Client
)

func init() {
	Addr := os.Getenv("REDIS_HOST") + ":" + os.Getenv("REDIS_PORT")
	Password := os.Getenv("REDIS_PASSWORD")
	DB, _ := strconv.Atoi(os.Getenv("REDIS_DB"))

	client := redis.NewClient(&redis.Options{
		Addr:     Addr,
		Password: Password,
		DB:       DB,
	})

	_, err := client.Ping().Result()

	if err != nil {
		panic("Redis ping 失败:" + err.Error())
	}

	Redis = client
}
